Change in openvpn[master]: Add support for user defined network namespace
A message that is not in the archive (sent off-list or not yet received): gerrit.1770986118000.I8b0d1cad7062856abcc40c4e16ec93b45295bbd3@...2715...
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to review the following change.
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow moving the tunnel interface into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 707 insertions(+), 46 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/1
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by ovpn-dco, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +2 -2
@@ -42,7 +42,7 @@/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +566 -43
963 lines not on this page · raw message
src/openvpn/networking_sitnl.h +105 -1
112 lines not on this page · raw message
src/openvpn/options.c +10 -0
@@ -6473,6 +6473,16 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +#if defined(TARGET_LINUX) + else if (streq(p[0], "netns") && p[1] && !p[2]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when SITNL is built-in" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + } +#endif else if (streq(p[0], "nice") && p[1] && !p[2]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -316,6 +316,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +11 -0
@@ -2169,6 +2169,17 @@set_nonblock (tt->fd);set_cloexec (tt->fd); tt->actual_name =string_alloc (ifr.ifr_name,NULL ); + +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (ctx->netns) + { +int ret =net_iface_move_netns (ifr.ifr_name, ctx->netns); +if (ret <0 ) + { +msg (M_WARN |M_ERRNO ,"Note: Cannot move dev %s to network namespace %s" , ifr.ifr_name, ctx->netns); + } + } +#endif /* if defined (TARGET_LINUX) && defined(ENABLE_SITNL) */ }return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 1: Code-Review-2
(26 comments)
Patchset:
PS1:
I stopped reviewing at some point. Enough to fix for now
File src/openvpn/dco.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/f5b745f0_c74ba00a?usp=email :
PS1, Line 394: msg(msglevel, "Note: --netns not supported by ovpn-dco, disabling data channel offload.");ovpn ? Or just "DCO"?
File src/openvpn/networking_sitnl.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/fa0e61b1_09e3ce72?usp=email :
PS1, Line 52: * NETNS_RUN_DIR, e.g. /var/run/netns/<name>).
Doxygen says networking_sitnl.h:52: warning: Unsupported xml/html tag <name> found
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/1e561559_8521c63f?usp=email :
PS1, Line 98: int openvpn_if_nametoindex(const char *ifname, int netnsid);
This is ALWAYS called with get_or_create_netnsid_sitnl, so just move all of that code inside and change the signature.
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/97ff67c1_781261b5?usp=email :
PS1, Line 74: #define NETNS_RUN_DIR "/var/run/netns"
Wouldn't /run be a better value here? /var/run is just a symlink nowadays AFAIK
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/289f0216_601a33c5?usp=email :
PS1, Line 206: msg(M_WARN, "%s: Network namespace %s does not exist\n", __func__, path);M_ERRNO?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/d1511ce1_4a61a209?usp=email :
PS1, Line 239: msg(M_WARN, "%s: Cannot open original network namespace\n", __func__);M_ERRNO?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/db2ee770_077ea5de?usp=email :
PS1, Line 247: msg(M_WARN, "%s: Cannot open network namespace \"%s\"\n", __func__, name);M_ERRNO
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/60e6c6bb_45c54b89?usp=email :
PS1, Line 254: msg(M_WARN, "%s: setting the network namespace \"%s\" failed\n", __func__, name);M_ERRNO
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/5e711262_50c89506?usp=email :
PS1, Line 272: msg(M_WARN, "%s: Cannot restore original network namespace\n", __func__);M_ERRNO
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/15d5672a_5f164ecd?usp=email :
PS1, Line 635: goto err;
just use return
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/e3edca05_87e906c4?usp=email :
PS1, Line 841: goto err;M_ERR is fatal
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/5ed22de4_b4c7950e?usp=email :
PS1, Line 848: goto err;M_ERR is fatal
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/7cb5d904_f6b98d2c?usp=email :
PS1, Line 914: if (netns)
These 4 lines (counting the netns assignment) are copied often enough that they should be moved to a function or macro.
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/48e4eb65_4e5b7e66?usp=email :
PS1, Line 928: msg(M_WARN, "%s: rtnl: cannot get ifindex for %s: %s", __func__, iface, strerror(errno));
Should use M_ERRNO instead of manually using strerror
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/e1d31283_33bdeb60?usp=email :
PS1, Line 950: ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
Just declare ret here. C has moved on...
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/f52dde96_e5b369fd?usp=email :
PS1, Line 953: goto err;
Just use return
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/e4633213_a3d2a888?usp=email :
PS1, Line 955: if (orig >= 0)
Also move to function or macro
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/3706333e_7b657959?usp=email :
PS1, Line 1002: err:
Unused label?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/a2a79f77_a7e3716c?usp=email :
PS1, Line 1019:
spurious empty line
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/99000be3_9e6be45b?usp=email :
PS1, Line 1064:
spurious empty line
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/7c543e33_d1045522?usp=email :
PS1, Line 1124: err:
Unused label
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/a9d4fe8c_8da527ff?usp=email :
PS1, Line 1833: goto err;
WHAT?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/57c51c0b_69ab4bb4?usp=email :
PS1, Line 1881: goto err;
lol
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/09b54618_34113780?usp=email :
PS1, Line 1903: return netnsid;
Hmm, why does clang-format not fix this?
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/cbd845cd_a862dec9?usp=email :
PS1, Line 6476: #if defined(TARGET_LINUX)
The documentation says it is a no-op on non-Linux, but as you implemented it is an error I think?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Mon, 16 Feb 2026 12:10:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 1:
(1 comment)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/330a0872_0cff1ab0?usp=email :
PS1, Line 1903: return netnsid;
Quoted 1 line
Hmm, why does clang-format not fix this?
Addressed in http://gerrit.openvpn.net/c/openvpn/+/1529
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Mon, 16 Feb 2026 12:25:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#2).
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow moving the tunnel interface into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 701 insertions(+), 80 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/2
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +2 -2
@@ -42,7 +42,7 @@/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +558 -77
973 lines not on this page · raw message
src/openvpn/networking_sitnl.h +109 -1
116 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6455,6 +6455,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when SITNL is built-in" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -316,6 +316,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +11 -0
@@ -2169,6 +2169,17 @@set_nonblock (tt->fd);set_cloexec (tt->fd); tt->actual_name =string_alloc (ifr.ifr_name,NULL ); + +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (ctx->netns) + { +int ret =net_iface_move_netns (ifr.ifr_name, ctx->netns); +if (ret <0 ) + { +msg (M_WARN |M_ERRNO ,"Note: Cannot move dev %s to network namespace %s" , ifr.ifr_name, ctx->netns); + } + } +#endif /* if defined (TARGET_LINUX) && defined(ENABLE_SITNL) */ }return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 2:
(24 comments)
File src/openvpn/dco.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/896aa530_aee37115?usp=email :
PS1, Line 394: msg(msglevel, "Note: --netns not supported by ovpn-dco, disabling data channel offload.");
Quoted 1 line
ovpn? Or just "DCO"?
Done
File src/openvpn/networking_sitnl.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/54e1d744_317f8b7a?usp=email :
PS1, Line 52: * NETNS_RUN_DIR, e.g. /var/run/netns/<name>).
Quoted 1 line
Doxygen says `networking_sitnl. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/dcdf2078_aa274ea0?usp=email :
PS1, Line 98: int openvpn_if_nametoindex(const char *ifname, int netnsid);
Quoted 1 line
This is ALWAYS called with
get_or_create_netnsid_sitnl, so just move all of that code inside and c […]
I'm not thrilled by the idea of having a function that does too much stuff so I only moved the call to get_or_create_netnsid_sitnl() inside.
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/fa0f2215_3cf98d28?usp=email :
PS1, Line 74: #define NETNS_RUN_DIR "/var/run/netns"
Quoted 1 line
Wouldn't
/runbe a better value here?/var/runis just a symlink nowadays AFAIK
indeed
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/f4d47f64_4f660ee1?usp=email :
PS1, Line 206: msg(M_WARN, "%s: Network namespace %s does not exist\n", __func__, path);
Quoted 1 line
M_ERRNO?
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/c43227fc_0359781b?usp=email :
PS1, Line 239: msg(M_WARN, "%s: Cannot open original network namespace\n", __func__);
Quoted 1 line
M_ERRNO?
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/67a2f3a1_46be9598?usp=email :
PS1, Line 247: msg(M_WARN, "%s: Cannot open network namespace \"%s\"\n", __func__, name);
Quoted 1 line
M_ERRNO
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/be497947_bd26b285?usp=email :
PS1, Line 254: msg(M_WARN, "%s: setting the network namespace \"%s\" failed\n", __func__, name);
Quoted 1 line
M_ERRNO
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/4c35413c_6640d246?usp=email :
PS1, Line 272: msg(M_WARN, "%s: Cannot restore original network namespace\n", __func__);
Quoted 1 line
M_ERRNO
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/742c386b_4519cc6f?usp=email :
PS1, Line 635: goto err;
Quoted 1 line
just use return
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/22e23784_c162668b?usp=email :
PS1, Line 841: goto err;
Quoted 1 line
M_ERRis fatal
M_ERRNO?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/8a284417_909fc242?usp=email :
PS1, Line 848: goto err;
Quoted 1 line
M_ERRis fatal
M_ERRNO?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/d3926303_567f83d5?usp=email :
PS1, Line 914: if (netns)
Quoted 1 line
These 4 lines (counting the netns assignment) are copied often enough that they should be moved to a […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/88485286_b7b56c97?usp=email :
PS1, Line 928: msg(M_WARN, "%s: rtnl: cannot get ifindex for %s: %s", __func__, iface, strerror(errno));
Quoted 1 line
Should use
M_ERRNOinstead of manually using strerror
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/f5ac3d5e_ae177443?usp=email :
PS1, Line 950: ret = sitnl_send(&req.n, 0, 0, NULL, NULL);
Quoted 1 line
Just declare ret here. C has moved on...
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/18e6b8dd_66e39679?usp=email :
PS1, Line 953: goto err;
Quoted 1 line
Just use return
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/9305239d_8149d39f?usp=email :
PS1, Line 955: if (orig >= 0)
Quoted 1 line
Also move to function or macro
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/43479fdf_4052fd95?usp=email :
PS1, Line 1002: err:
Quoted 1 line
Unused label?
SITNL_ADDATTR() requires a label
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/164779a4_0a0706ba?usp=email :
PS1, Line 1019:
Quoted 1 line
spurious empty line
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/034b03f7_9d56a11c?usp=email :
PS1, Line 1064:
Quoted 1 line
spurious empty line
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/c991facb_65fb1024?usp=email :
PS1, Line 1124: err:
Quoted 1 line
Unused label
SITNL_ADDATTR() requires a label
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/9da49ebb_0c7cdb54?usp=email :
PS1, Line 1833: goto err;
Quoted 1 line
WHAT?
Whoops
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/a803d839_9934efff?usp=email :
PS1, Line 1881: goto err;
Quoted 1 line
lol
Done
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/2b61fd19_da804455?usp=email :
PS1, Line 6476: #if defined(TARGET_LINUX)
Quoted 1 line
The documentation says it is a no-op on non-Linux, but as you implemented it is an error I think?
indeed
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 26 Feb 2026 09:48:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 2: Code-Review-2
(6 comments)
File src/openvpn/networking_sitnl.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/bb1d8a23_20125c14?usp=email :
PS1, Line 98: int openvpn_if_nametoindex(const char *ifname, int netnsid);
Quoted 1 line
I'm not thrilled by the idea of having a function that does too much stuff so I only moved the call […]
Done
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/6558e3ae_b6c53a15?usp=email :
PS1, Line 841: goto err;
Quoted 1 line
M_ERRNO?
This changes it from effectively M_FATAL | M_ERRNO to M_INFO | M_ERRNO. That feels like a big change. If you want the error to be fatal, then just remove the code after the msg() call. If you do not want it to be fatal, then use M_WARN | M_ERRNO. M_INFO feels wrong.
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/6bd42df7_ac3131a1?usp=email :
PS1, Line 1002: err:
Quoted 1 line
SITNL_ADDATTR()requires a label
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/623af649_3ec0329e?usp=email :
PS1, Line 1124: err:
Quoted 1 line
SITNL_ADDATTR()requires a label
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/3c69f209_c727ee44?usp=email :
PS1, Line 1903: return netnsid;
Quoted 1 line
Addressed in http://gerrit.openvpn. […]
Done
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/8758f6bd_4e04d658?usp=email :
PS2, Line 206: msg(M_ERRNO, "%s: Network namespace %s does not exist\n", __func__, path);
Hmm, why did you change M_WARN to M_ERRNO? That means the same as M_INFO | M_ERRNO AFAICT. So I would have expected you to retain the M_WARN. M_ERRNO is not a level but an additional flag that ensures that strerr output is appended.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Thu, 26 Feb 2026 11:37:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#3).
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow moving the tunnel interface into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 701 insertions(+), 80 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/3
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +2 -2
@@ -42,7 +42,7 @@/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +558 -77
973 lines not on this page · raw message
src/openvpn/networking_sitnl.h +109 -1
116 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6455,6 +6455,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when SITNL is built-in" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -316,6 +316,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +11 -0
@@ -2169,6 +2169,17 @@set_nonblock (tt->fd);set_cloexec (tt->fd); tt->actual_name =string_alloc (ifr.ifr_name,NULL ); + +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (ctx->netns) + { +int ret =net_iface_move_netns (ifr.ifr_name, ctx->netns); +if (ret <0 ) + { +msg (M_WARN |M_ERRNO ,"Note: Cannot move dev %s to network namespace %s" , ifr.ifr_name, ctx->netns); + } + } +#endif /* if defined (TARGET_LINUX) && defined(ENABLE_SITNL) */ }return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 3:
(3 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/122e5461_ae4d3b5a?usp=email :
PS1, Line 841: goto err;
Quoted 1 line
This changes it from effectively
M_FATAL | M_ERRNOtoM_INFO | M_ERRNO. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/05bd4cdb_f0807205?usp=email :
PS1, Line 848: goto err;
Quoted 1 line
M_ERRNO?
Done
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/a653993b_b8776da3?usp=email :
PS2, Line 206: msg(M_ERRNO, "%s: Network namespace %s does not exist\n", __func__, path);
Quoted 1 line
Hmm, why did you change
M_WARNtoM_ERRNO? That means the same asM_INFO | M_ERRNOAFAICT. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 26 Feb 2026 13:39:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 3: Code-Review-1
(4 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/57e35eeb_25accb45?usp=email :
PS3, Line 638: SITNL_ADDATTR(&req.n, sizeof(req), IFLA_TARGET_NETNSID, &netnsid, 4);
Yes, sizeof(int) == 4, but do we need to hard-code this here?
This issue is all over the code, only noting the first instance I found.
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/cc6d4520_806e8ed9?usp=email :
PS3, Line 1172: netns_restore(orig);
Why do we skip the restore on error?
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/6b59d92f_2d13ab27?usp=email :
PS3, Line 1347: msg(M_WARN, "%s: cannot get ifindex for %s: %s", __func__, np(iface), strerror(errno));
Please switch to M_ERRNO as well
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/8524456a_c0f153f1?usp=email :
PS3, Line 6461: msg(M_WARN, "NOTE: --netns is supported only on Linux when SITNL is built-in");
I think "when SITNL support is enabled" would sound better
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Mar 2026 11:34:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: its_Giaan.
plaisthos has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 3:
(1 comment)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/bc95d175_56010af8?usp=email :
PS3, Line 638: SITNL_ADDATTR(&req.n, sizeof(req), IFLA_TARGET_NETNSID, &netnsid, 4);
Quoted 1 line
Yes, sizeof(int) == 4, but do we need to hard-code this here? […]
I think we should seriously consider adding functions that are type like SITNL_ADDATTR_U32 and so on to avoid the issue entirely.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Mar 2026 11:42:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, its_Giaan.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow moving the tunnel interface into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 712 insertions(+), 81 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/4
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +2 -2
@@ -42,7 +42,7 @@/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +569 -78
1,006 lines not on this page · raw message
src/openvpn/networking_sitnl.h +109 -1
116 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6462,6 +6462,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +11 -0
@@ -2178,6 +2178,17 @@set_nonblock (tt->fd);set_cloexec (tt->fd); tt->actual_name =string_alloc (ifr.ifr_name,NULL ); + +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (ctx->netns) + { +int ret =net_iface_move_netns (ifr.ifr_name, ctx->netns); +if (ret <0 ) + { +msg (M_WARN |M_ERRNO ,"Note: Cannot move dev %s to network namespace %s" , ifr.ifr_name, ctx->netns); + } + } +#endif /* if defined (TARGET_LINUX) && defined(ENABLE_SITNL) */ }return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 3:
(4 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/229b5b69_31a021e5?usp=email :
PS3, Line 638: SITNL_ADDATTR(&req.n, sizeof(req), IFLA_TARGET_NETNSID, &netnsid, 4);
Quoted 1 line
I think we should seriously consider adding functions that are type like
SITNL_ADDATTR_U32and so on […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/d0985676_7aa42374?usp=email :
PS3, Line 1172: netns_restore(orig);
Quoted 1 line
Why do we skip the restore on error?
Forgetfulness
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/80003e3d_ecd05fe7?usp=email :
PS3, Line 1347: msg(M_WARN, "%s: cannot get ifindex for %s: %s", __func__, np(iface), strerror(errno));
Quoted 1 line
Please switch to
M_ERRNOas well
Done
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/9bf0c4d3_06bedd67?usp=email :
PS3, Line 6461: msg(M_WARN, "NOTE: --netns is supported only on Linux when SITNL is built-in");
Quoted 1 line
I think "when SITNL support is enabled" would sound better
I went for "is supported only on Linux when compiled with SITNL"
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Mar 2026 16:22:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 4: Code-Review-1
(13 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/4314739e_2d4bc1d9?usp=email :
PS4, Line 771: if (ret < 0)
Redundant code.
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/bdeed08b_be6f179c?usp=email :
PS4, Line 819: if (ret < 0)
redundant code
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/dd19d5b9_09ff231b?usp=email :
PS4, Line 1137: netns_restore(orig);
instead just move the code around so the switch happens after the check
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/efa59517_408ec8ff?usp=email :
PS4, Line 1169: if (ret < 0)
redundant code
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/eb0d21db_0305708b?usp=email :
PS4, Line 1211: netns_restore(orig);
restore needs to be after err:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/c1f79458_0f7d935d?usp=email :
PS4, Line 1247: netns_restore(orig);
restore needs to be after err:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/dcedc153_51d7fe41?usp=email :
PS4, Line 1283: netns_restore(orig);
move the netns_switch to after the parameter checks
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/37b3e127_ecd5e4c8?usp=email :
PS4, Line 1321: netns_restore(orig);
needs to be after err:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/2da76258_bc75db17?usp=email :
PS4, Line 1416: netns_restore(orig);
move switch to after parameter check
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/37f50a5e_1a48206b?usp=email :
PS4, Line 1464: netns_restore(orig);
after err:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/20b0928d_d826d6f3?usp=email :
PS4, Line 1952: netns_restore(orig);
restore before switch
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/a4d99beb_485b5051?usp=email :
PS4, Line 1969: if (ret < 0)
redundant code
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/6eeabe14_8951b5a9?usp=email :
PS4, Line 6468: msg(M_WARN, "NOTE: --netns is supported only on Linux when compiled with SITNL");
I would go for "SITNL support"
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Mar 2026 10:21:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 4:
(1 comment)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/df3c47bd_c6afa6db?usp=email :
PS4, Line 6468: msg(M_WARN, "NOTE: --netns is supported only on Linux when compiled with SITNL");
Quoted 1 line
I would go for "SITNL support"
ordex disagreed on IRC. And he is the authority, so let's leave it.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Mar 2026 10:39:58 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow moving the tunnel interface into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 678 insertions(+), 81 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/5
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +2 -2
@@ -42,7 +42,7 @@/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +535 -78
966 lines not on this page · raw message
src/openvpn/networking_sitnl.h +109 -1
116 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6462,6 +6462,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +11 -0
@@ -2178,6 +2178,17 @@set_nonblock (tt->fd);set_cloexec (tt->fd); tt->actual_name =string_alloc (ifr.ifr_name,NULL ); + +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (ctx->netns) + { +int ret =net_iface_move_netns (ifr.ifr_name, ctx->netns); +if (ret <0 ) + { +msg (M_WARN |M_ERRNO ,"Note: Cannot move dev %s to network namespace %s" , ifr.ifr_name, ctx->netns); + } + } +#endif /* if defined (TARGET_LINUX) && defined(ENABLE_SITNL) */ }return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 5:
(12 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/167513fa_e7d6d350?usp=email :
PS4, Line 771: if (ret < 0)
Quoted 1 line
Redundant code.
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/7eddcf9c_aaa945e8?usp=email :
PS4, Line 819: if (ret < 0)
Quoted 1 line
redundant code
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/537e9aad_7a6ad766?usp=email :
PS4, Line 1137: netns_restore(orig);
Quoted 1 line
instead just move the code around so the switch happens after the check
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/f7070273_3fab86e7?usp=email :
PS4, Line 1169: if (ret < 0)
Quoted 1 line
redundant code
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/670cfaf3_d7b151a8?usp=email :
PS4, Line 1211: netns_restore(orig);
Quoted 1 line
restore needs to be after err:
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/cb3e6ac1_b795495f?usp=email :
PS4, Line 1247: netns_restore(orig);
Quoted 1 line
restore needs to be after err:
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/1ae478b0_27bb0047?usp=email :
PS4, Line 1283: netns_restore(orig);
Quoted 1 line
move the
netns_switchto after the parameter checks
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/0535a454_21dfab59?usp=email :
PS4, Line 1321: netns_restore(orig);
Quoted 1 line
needs to be after err:
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/114af87d_61ddd36d?usp=email :
PS4, Line 1416: netns_restore(orig);
Quoted 1 line
move switch to after parameter check
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/c68c9df0_09f15400?usp=email :
PS4, Line 1464: netns_restore(orig);
Quoted 1 line
after err:
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/c933e7c7_5cf78d92?usp=email :
PS4, Line 1952: netns_restore(orig);
Quoted 1 line
restore before switch
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/21b10505_c0d56d20?usp=email :
PS4, Line 1969: if (ret < 0)
Quoted 1 line
redundant code
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Mar 2026 16:15:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 5: Code-Review-1
(4 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/2c442d92_883b2fcf?usp=email :
PS5, Line 281: close(orig_fd);
The code is redundant. You do exactly the same in the non-error case.
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/b5d060c5_af6a3dc7?usp=email :
PS5, Line 766: if (netns_fd >= 0)
Needs to be moved below err:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/348706a1_45915420?usp=email :
PS5, Line 809: if (netns_fd >= 0)
Needs to be moved below err:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/33d945d2_4b57e115?usp=email :
PS5, Line 1073: if (netns_fd >= 0)
Needs to be moved below err:
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 18 Mar 2026 16:30:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#6).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow moving the tunnel interface into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 673 insertions(+), 81 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/6
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +2 -2
@@ -42,7 +42,7 @@/* Only the iproute2 backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +530 -78
961 lines not on this page · raw message
src/openvpn/networking_sitnl.h +109 -1
116 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6462,6 +6462,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +11 -0
@@ -2178,6 +2178,17 @@set_nonblock (tt->fd);set_cloexec (tt->fd); tt->actual_name =string_alloc (ifr.ifr_name,NULL ); + +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (ctx->netns) + { +int ret =net_iface_move_netns (ifr.ifr_name, ctx->netns); +if (ret <0 ) + { +msg (M_WARN |M_ERRNO ,"Note: Cannot move dev %s to network namespace %s" , ifr.ifr_name, ctx->netns); + } + } +#endif /* if defined (TARGET_LINUX) && defined(ENABLE_SITNL) */ }return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 5:
(4 comments)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/d4fd6d44_e633ccac?usp=email :
PS5, Line 281: close(orig_fd);
Quoted 1 line
The code is redundant. You do exactly the same in the non-error case.
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/71fccbb4_f14d9dec?usp=email :
PS5, Line 766: if (netns_fd >= 0)
Quoted 1 line
Needs to be moved below err:
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/2c710d4d_b0b4bad4?usp=email :
PS5, Line 809: if (netns_fd >= 0)
Quoted 1 line
Needs to be moved below err:
Done
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/44d96a0e_641d34b2?usp=email :
PS5, Line 1073: if (netns_fd >= 0)
Quoted 1 line
Needs to be moved below err:
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 19 Mar 2026 09:03:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 6: Code-Review-1
(6 comments)
Patchset:
PS6:
Mostly done with obvious problems. Doing some testing now and noted some things about the actual behavior. Note that these are not necessarily objective problems but more my opinion of how I would expect it to work. So let me know what you think 😊
File src/openvpn/networking.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/a54ba7ff_66357771?usp=email :
PS6, Line 42: /* Only the iproute2 backend implements these functions, This comment is outdated
File src/openvpn/networking_sitnl.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/8c83021c_80e04de6?usp=email :
PS6, Line 113: * (/var/run/netns)./run/netns
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/bd778cd2_164b398c?usp=email :
PS6, Line 207: return -1;
Note that this return value is meaningless since no code ever checks it. I would suggest that a non-existent namespace should be a fatal error?
File src/openvpn/tun.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/2eb2828a_8a3cf902?usp=email :
PS6, Line 2185: int ret = net_iface_move_netns(ifr.ifr_name, ctx->netns);
One interesting problem I encountered is that the usual way of auto-naming tun devices doesn't really work with --netns. Since the device is created in a different namespace it can't know whether there is already a device with the same name in the target namespace.
Not sure whether we can work around this? If not, maybe we should document this? Might be a niche use-case (outside of testing).
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/3b67e7d2_771ff340?usp=email :
PS6, Line 2188: msg(M_WARN | M_ERRNO, "Note: Cannot move dev %s to network namespace %s", ifr.ifr_name, ctx->netns);
I would go for M_ERR here. I would consider this a fatal error.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Thu, 19 Mar 2026 12:30:40 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#7).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow interface creation into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 610 insertions(+), 82 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/7
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +3 -3
@@ -39,10 +39,10 @@typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ -/* Only the iproute2 backend implements these functions, +/* Only the iproute2 and sitnl backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +482 -78
907 lines not on this page · raw message
src/openvpn/networking_sitnl.h +91 -1
98 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6462,6 +6462,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +13 -0
@@ -2082,6 +2082,13 @@ }else { +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +int orig_fd =-1 ; +if (ctx->netns) + { + orig_fd =netns_switch (ctx); + } +#endif /* if defined(TARGET_LINUX) && defined(ENABLE_SITNL) */ /* * Process --dev-node */
@@ -2098,6 +2105,12 @@ {msg (M_ERR ,"ERROR: Cannot open TUN/TAP dev %s" , node); } +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (orig_fd !=-1 ) + { +netns_restore (orig_fd); + } +#endif /* * Process --tun-ipv6
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 7
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 7:
(5 comments)
File src/openvpn/networking.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/4ec40e14_ab031002?usp=email :
PS6, Line 42: /* Only the iproute2 backend implements these functions,
Quoted 1 line
This comment is outdated
Done
File src/openvpn/networking_sitnl.h:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/7944c4f7_347e1ae4?usp=email :
PS6, Line 113: * (/var/run/netns).
Quoted 1 line
/run/netns
This part has been removed, so no fix longer needed.
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/c17f7f0d_724d403e?usp=email :
PS6, Line 207: return -1;
Quoted 1 line
Note that this return value is meaningless since no code ever checks it. […]
Done
File src/openvpn/tun.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/32fdbd8e_d4ad4523?usp=email :
PS6, Line 2185: int ret = net_iface_move_netns(ifr.ifr_name, ctx->netns);
Quoted 1 line
One interesting problem I encountered is that the usual way of auto-naming tun devices doesn't reall […]
Thanks for spotting this, that was indeed an intresting problem.
We got around this by creating the interface directly into the target namespace, so auto-naming will continue to work as usually.
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/ad76eec1_abbaa8dc?usp=email :
PS6, Line 2188: msg(M_WARN | M_ERRNO, "Note: Cannot move dev %s to network namespace %s", ifr.ifr_name, ctx->netns);
Quoted 1 line
I would go for
M_ERRhere. I would consider this a fatal error.
This part has been removed, so no fix longer needed.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 7
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Mar 2026 16:20:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 7: Code-Review-1
(1 comment)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/9c619d65_e3b07bdc?usp=email :
PS7, Line 206: msg(M_FATAL | M_ERRNO, "%s: Network namespace %s does not exist", __func__, path);#define M_ERR (M_FATAL | M_ERRNO)
Please use that.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 7
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Mar 2026 16:26:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#8).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow interface creation into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 610 insertions(+), 82 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/8
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +3 -3
@@ -39,10 +39,10 @@typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ -/* Only the iproute2 backend implements these functions, +/* Only the iproute2 and sitnl backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +482 -78
907 lines not on this page · raw message
src/openvpn/networking_sitnl.h +91 -1
98 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6462,6 +6462,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +13 -0
@@ -2082,6 +2082,13 @@ }else { +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +int orig_fd =-1 ; +if (ctx->netns) + { + orig_fd =netns_switch (ctx); + } +#endif /* if defined(TARGET_LINUX) && defined(ENABLE_SITNL) */ /* * Process --dev-node */
@@ -2098,6 +2105,12 @@ {msg (M_ERR ,"ERROR: Cannot open TUN/TAP dev %s" , node); } +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (orig_fd !=-1 ) + { +netns_restore (orig_fd); + } +#endif /* * Process --tun-ipv6
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 8
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 8:
(1 comment)
File src/openvpn/networking_sitnl.c:
http://gerrit.openvpn.net/c/openvpn/+/1521/comment/30afdc96_915e2f09?usp=email :
PS7, Line 206: msg(M_FATAL | M_ERRNO, "%s: Network namespace %s does not exist", __func__, path);
Quoted 1 line
#define M_ERR (M_FATAL | M_ERRNO)[…]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 8
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 24 Mar 2026 16:35:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 8: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 8
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 25 Mar 2026 12:14:12 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH v8 1/1 Add support for user defined network namespace
In reply to a message not in the archiveFrom: Gianmarco De Gregori <[email protected]...>
Introduce the --netns option to allow interface creation into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1521
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1521
This mail reflects revision 8 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Move the created tunnel interface into the specified network + namespace. The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +3 -3
@@ -39,10 +39,10 @@typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ -/* Only the iproute2 backend implements these functions, +/* Only the iproute2 and sitnl backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +482 -78
907 lines not on this page · raw message
src/openvpn/networking_sitnl.h +91 -1
98 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6462,6 +6462,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +13 -0
@@ -2082,6 +2082,13 @@ }else { +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +int orig_fd =-1 ; +if (ctx->netns) + { + orig_fd =netns_switch (ctx); + } +#endif /* if defined(TARGET_LINUX) && defined(ENABLE_SITNL) */ /* * Process --dev-node */
@@ -2098,6 +2105,12 @@ {msg (M_ERR ,"ERROR: Cannot open TUN/TAP dev %s" , node); } +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (orig_fd !=-1 ) + { +netns_restore (orig_fd); + } +#endif /* * Process --tun-ipv6
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#9).
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow interface creation into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 610 insertions(+), 82 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/9
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Specify the network namespace in which the tunnel interface will be created. + The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +3 -3
@@ -39,10 +39,10 @@typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ -/* Only the iproute2 backend implements these functions, +/* Only the iproute2 and sitnl backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +482 -78
907 lines not on this page · raw message
src/openvpn/networking_sitnl.h +91 -1
98 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6488,6 +6488,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +13 -0
@@ -2082,6 +2082,13 @@ }else { +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +int orig_fd =-1 ; +if (ctx->netns) + { + orig_fd =netns_switch (ctx); + } +#endif /* if defined(TARGET_LINUX) && defined(ENABLE_SITNL) */ /* * Process --dev-node */
@@ -2098,6 +2105,12 @@ {msg (M_ERR ,"ERROR: Cannot open TUN/TAP dev %s" , node); } +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (orig_fd !=-1 ) + { +netns_restore (orig_fd); + } +#endif /* * Process --tun-ipv6
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 9
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
to look at the new patch set (#10).
Change subject: Add support for user defined network namespace
......................................................................
Add support for user defined network namespace
Introduce the --netns option to allow interface creation into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
---
M doc/man-sections/vpn-network-options.rst
M src/openvpn/dco.c
M src/openvpn/networking.h
M src/openvpn/networking_sitnl.c
M src/openvpn/networking_sitnl.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
8 files changed, 610 insertions(+), 82 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/1521/10
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Specify the network namespace in which the tunnel interface will be created. + The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +3 -3
@@ -39,10 +39,10 @@typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ -/* Only the iproute2 backend implements these functions, +/* Only the iproute2 and sitnl backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +482 -78
907 lines not on this page · raw message
src/openvpn/networking_sitnl.h +91 -1
98 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6488,6 +6488,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +13 -0
@@ -2082,6 +2082,13 @@ }else { +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +int orig_fd =-1 ; +if (ctx->netns) + { + orig_fd =netns_switch (ctx); + } +#endif /* if defined(TARGET_LINUX) && defined(ENABLE_SITNL) */ /* * Process --dev-node */
@@ -2098,6 +2105,12 @@ {msg (M_ERR ,"ERROR: Cannot open TUN/TAP dev %s" , node); } +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (orig_fd !=-1 ) + { +netns_restore (orig_fd); + } +#endif /* * Process --tun-ipv6
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email )
Change subject: Add support for user defined network namespace
......................................................................
Patch Set 10: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1521?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8b0d1cad7062856abcc40c4e16ec93b45295bbd3
Gerrit-Change-Number: 1521
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Tue, 31 Mar 2026 10:35:05 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH v10 1/1 Add support for user defined network namespace
In reply to a message not in the archiveFrom: Gianmarco De Gregori <[email protected]...>
Introduce the --netns option to allow interface creation into a user-defined network namespace.
This allows the VPN data plane to be isolated from the main OpenVPN process namespace.
The current netlink library integration supports interface creation and deletion in a target namespace. However, subsequent configuration operations (e.g. address or mtu set) are executed in the caller's namespace, as they rely on the default netlink socket context. As a result, interface-related configuration performed after creation may be applied in the wrong namespace.
Introduce helper functions to temporarily switch the process to the requested network namespace using setns(2), execute the required netlink operations, and then restore the original namespace. The namespace switch is temporary and scoped to each netlink operation. Once the operation completes, the original namespace is restored to preserve the process execution context.
Note: This feature is Linux-only and depends on setns(2). It is not compatible (yet) with Data Channel Offload (DCO).
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1521
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1521
This mail reflects revision 10 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
doc/man-sections/vpn-network-options.rst +6 -0
@@ -304,6 +304,12 @@ Specify the link layer address, more commonly known as the MAC address. Only applied to TAP devices. +--netns name + Specify the network namespace in which the tunnel interface will be created. + The namespace must already exist. + + (Supported on Linux only, on other platforms this is a no-op). + --persist-tun Don't close and reopen TUN/TAP device or run up/down scripts across :code:`SIGUSR1` or ``--ping-restart`` restarts.
src/openvpn/dco.c +6 -0
@@ -388,6 +388,12 @@ ret); } } + +if (o->netns) + { +msg (msglevel,"Note: --netns not supported by DCO, disabling data channel offload." ); +return false; + }#endif /* if defined(_WIN32) */ #if defined(HAVE_LIBCAPNG )
src/openvpn/networking.h +3 -3
@@ -39,10 +39,10 @@typedef void *openvpn_net_iface_t ;#endif /* ifdef ENABLE_SITNL */ -/* Only the iproute2 backend implements these functions, +/* Only the iproute2 and sitnl backend implements these functions, * the rest can rely on these stubs */ -#if !defined(ENABLE_IPROUTE ) +#if !defined(ENABLE_IPROUTE ) && !defined(ENABLE_SITNL ) || defined(TARGET_ANDROID )static inline int net_ctx_init (struct context *c,openvpn_net_ctx_t *ctx) {
@@ -63,7 +63,7 @@ { (void )ctx; } -#endif /* !defined(ENABLE_IPROUTE) */ +#endif /* !defined(ENABLE_IPROUTE) && !defined(ENABLE_SITNL) || defined(TARGET_ANDROID) */ #if defined(ENABLE_SITNL ) || defined(ENABLE_IPROUTE )
src/openvpn/networking_sitnl.c +482 -78
907 lines not on this page · raw message
src/openvpn/networking_sitnl.h +91 -1
98 lines not on this page · raw message
src/openvpn/options.c +8 -0
@@ -6488,6 +6488,14 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->mtu_test = true; } +else if (streq (p[0 ],"netns" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --netns is supported only on Linux when compiled with SITNL" ); +#endif +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->netns = p[1 ]; + }else if (streq (p[0 ],"nice" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_NICE );
src/openvpn/options.h +1 -0
@@ -315,6 +315,7 @@struct dns_options dns_options; +const char *netns;bool remote_random;const char *ipchange;const char *dev;
src/openvpn/tun.c +13 -0
@@ -2082,6 +2082,13 @@ }else { +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +int orig_fd =-1 ; +if (ctx->netns) + { + orig_fd =netns_switch (ctx); + } +#endif /* if defined(TARGET_LINUX) && defined(ENABLE_SITNL) */ /* * Process --dev-node */
@@ -2098,6 +2105,12 @@ {msg (M_ERR ,"ERROR: Cannot open TUN/TAP dev %s" , node); } +#if defined(TARGET_LINUX ) && defined(ENABLE_SITNL ) +if (orig_fd !=-1 ) + { +netns_restore (orig_fd); + } +#endif /* * Process --tun-ipv6